Repository navigation
Fix #15312: internalError for possible unknown macro at end of file - #9118
ludviggunne wants to merge 2 commits into
Conversation
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
The new check in findGarbageCode() misses a NAME { ... } that comes right after a function body. When the loop skips a { ... } block it sets statementStart = false, so the token after void f() {} is never treated as the start of a statement. void f() {}\nABC { g() } still gives the old internalError (AST cyclic dependency), and a macro after a function is a common case for this ticket. I found no false positives on the namespace-scope code I tried (enum {..};, union {..};, extern "C" {}, namespace A::inline B {}, inline namespace, concepts, modules), and the full testrunner passes.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | Code after a function body is not treated as a statement start, so void f() {}\nABC { g() } still gives internalError |
AI review | lib/tokenize.cpp:9502 |
🆕 New (false negative) |
@ludviggunne, please fix, resolve or reply to the open and new comments: #1.
For #1 (false negative), it is enough to create a Trac ticket and link it here. It does not need to be fixed in this PR.
Testing
Built cppcheck and testrunner from pr/ and cppcheck from base/.
./testrunner -q(all tests): 0 failed.- I compared PR and base on about 25 small files at namespace scope. The new check handles these:
int x;\nABC { g() },struct S { int a; };\nABC { g() }andnamespace { int a{1}; } b{2}. The first two now giveunknownMacroand the third givessyntaxError(base gave ASTinternalErrorfor all three). No new false positives.
Not caught (the false negative):
// f1.cpp
void f() {}
ABC { g() }$ /work/pr/cppcheck -q f1.cpp
f1.cpp:2:5: error: Internal error. AST cyclic dependency. [internalError]
void f() {} x{a} fails the same way: it gives the same internalError as base.
Related: asm { nop } still gives internalError, because asm is a keyword. _asm/__asm { ... } now give syntaxError instead of internalError.
Automated review of 7809a37 by Claude. The pull request was built and tested locally.
| continue; | ||
| } | ||
| tok = tok->link(); | ||
| statementStart = false; |
There was a problem hiding this comment.
AI review
After a skipped { ... } block, statementStart is set to false. That is correct for struct S {..} s;, but not after a function body or a class X {} that ends without ;. As a result the check never runs on the next statement:
void f() {}
ABC { g() }This still gives internalError: AST cyclic dependency. The same code after int x; gives unknownMacro, as intended. A macro block that follows a function is probably the most common form of this ticket.
Suggested fix: after a skipped block whose { is preceded by ) (or by const, override, noexcept and so on), set statementStart to true. Please also add a test for this case.
No description provided.